using System;
using UnityEngine;
using UnityEngine.UI;

namespace UI
{
    public class SetPanel : UIBase
    {
        private Button _btnSet;
        private Image _imgBg;
        private Button _btnClose;
        private Toggle _togAudio;
        private Slider _sldVolume;
        private Button _btnExit;
        private Text _textAudio;
        private Text _textVolume;

        void Start()
        {
            _btnSet = transform.Find("BtnSet").GetComponent<Button>();
            _imgBg = transform.Find("ImgBg").GetComponent<Image>();
            _btnClose = transform.Find("BtnClose").GetComponent<Button>();
            _togAudio = transform.Find("TogAudio").GetComponent<Toggle>();
            _sldVolume = transform.Find("SldVolume").GetComponent<Slider>();
            _btnExit = transform.Find("BtnExit").GetComponent<Button>();
            _textAudio = transform.Find("TextAudio").GetComponent<Text>();
            _textVolume = transform.Find("TextVolume").GetComponent<Text>();
            
            _btnSet.onClick.AddListener(SetPanelShowClick);
            _btnClose.onClick.AddListener(ClosePanelClick);
            _btnExit.onClick.AddListener(QuitClick);
            _togAudio.onValueChanged.AddListener(AudioToggle);
            _sldVolume.onValueChanged.AddListener(VolumeSlider);
            SetPanelActive(false);
        }

        private void VolumeSlider(float value)
        {
            
        }

        private void AudioToggle(bool active)
        {
            
        }

        private void QuitClick()
        {
            Debug.Log("退出");
            Application.Quit();
        }

        private void ClosePanelClick()
        {
            SetPanelActive(false);
        }

        void Update()
        {
        }

        private void SetPanelShowClick()
        {
            SetPanelActive(true);
        }

        private void SetPanelActive(bool active)
        {
            _imgBg.gameObject.SetActive(active);
            _btnClose.gameObject.SetActive(active);
            _togAudio.gameObject.SetActive(active);
            _sldVolume.gameObject.SetActive(active);
            _btnExit.gameObject.SetActive(active);
            _textAudio.gameObject.SetActive(active);
            _textVolume.gameObject.SetActive(active);
        }
    }
}